Inoculator = Widget.extend({
	ctor:function(parent){
		this._super();
		parent.addChild(this,7);
		this.setTag(TAG_INOCULATOR_NODE);
		this.init();
	},

	init : function(){
		this.setVisible(false);
		this.setCascadeOpacityEnabled(true);
		
		var inoculator1 =  new Button(this, 6, TAG_INOCULATOR1, "#run/inoculator3.png",this.callback);//针头
		inoculator1.setPosition(cc.p(-185,0));
		inoculator1.setScale(0.15);
		
		var inoculator2 =  new Button(this, 2, TAG_INOCULATOR, "#run/inoculator2.png",this.callback);//活塞
		inoculator2.setPosition(50,3);
		inoculator2.setScale(0.15);
		
		
		var inoculator3 =  new Button(this, 5, TAG_INOCULATOR2, "#run/inoculator1.png",this.callback);
		inoculator3.setScale(0.15);
		
//		var inoculator3 = new cc.Sprite("#run/inoculator1.png");
//		inoculator3.setPosition(cc.p(0,0));
//		this.addChild(inoculator3,5);
//		inoculator3.setScale(0.15);
	},
	xuanzhuan:function(){
		var frames=[];
		for (i=1;i<=3;i++){
			var str ="inoculator/"+i+".png";
			var frame=cc.spriteFrameCache.getSpriteFrame(str);
			frames.push(frame);
		}
		var animation = new cc.Animation(frames,0.1);//负责动画序列
		var action = new cc.Animate(animation);//帧动画的动作创建
		return action;		
	},
	callback:function(p){
		var action = gg.flow.flow.action;
		var func = cc.callFunc(this.actionDone, this);	
		func.retain();
		switch(p.getTag()){	
		case TAG_INOCULATOR:
			if(action==ACTION_DO1){
				var yimi = ll.run.getChildByTag(TAG_YIMI);
				yimi.runAction(cc.rotateTo(1,60));
				
				var seq = cc.sequence(cc.spawn(cc.moveTo(1,cc.p(750,350)),cc.rotateTo(1,-30)),cc.moveTo(1.5,cc.p(610,275)),cc.callFunc(function(){
					var seq1 = cc.sequence(func,cc.moveBy(1,cc.p(30,0)));
					p.runAction(seq1);
				},this),cc.delayTime(1.2),cc.moveTo(1.5,750,350),cc.callFunc(function(){
					var yimi = this.getChildByTag(TAG_SHOW);
					yimi.runAction(cc.spawn(cc.moveTo(1.2,cc.p(-90,0)),cc.rotateTo(1.2,90)));
				},this),cc.spawn(cc.moveTo(1,cc.p(600,320)),cc.rotateTo(1,-90)),cc.callFunc(function(){
					var yimi = ll.run.getChildByTag(TAG_YIMI);
					yimi.removeFromParent(true);
					this.flowNext();
				},this));
				this.runAction(seq);
			}else if(action==ACTION_DO2){
				var seq = cc.sequence(cc.callFunc(function(){
					p.runAction(func);
				},this),cc.moveTo(3,cc.p(80,3)),cc.delayTime(5),cc.callFunc(function(){
					this.flowNext();
				},this));
				p.runAction(seq);
				
			}
			break;
		case TAG_INOCULATOR1:
			var seq = cc.sequence(cc.callFunc(function(){
				p.runAction(this.xuanzhuan());
			},this),cc.moveTo(1,cc.p(-220,0)),cc.callFunc(function(){
				this.flowNext();
				p.removeFromParent(true);
			},this));
			p.runAction(seq);
	     	break;
	     	
		case TAG_INOCULATOR2:
			var seq = cc.sequence(cc.callFunc(function(){
				p.runAction(func);
			},this),cc.moveTo(3,cc.p(150,3)),cc.callFunc(function(){
				this.flowNext();
			},this));
			this.getChildByTag(TAG_INOCULATOR).runAction(seq);
		break;
		}
	},
	actionDone:function(p){
		var action = gg.flow.flow.action;
		var func = cc.callFunc(this.actionDone, this);
		switch(p.getTag()){
		case TAG_INOCULATOR:
		if(action==ACTION_DO1){
			var yimi = new cc.Sprite("#run/cly_line1.png");
			yimi.setPosition(cc.p(-100,-25));
			yimi.setScale(0.3);
			yimi.setRotation(30);
			this.addChild(yimi,1,TAG_SHOW);
			yimi.runAction(cc.spawn(cc.moveTo(1,cc.p(-90,-10)),cc.scaleTo(1,1)));
		}else if(action==ACTION_DO2){
			var yehua = new cc.Sprite("#run/yehua.png");
			yehua.setPosition(cc.p(-100,0));
			yehua.setAnchorPoint(0, 0.5);
			yehua.setScale(0.4,0.5);
			yehua.setOpacity(0);
			this.addChild(yehua);
			var seq = cc.sequence(cc.delayTime(0.5),cc.fadeIn(0.5),cc.callFunc(function(){
				var show = new ShowTip("压强增大,乙醚液化" ,cc.p(750,250));
			},this),cc.scaleTo(2,0.22,0.5));
			yehua.runAction(seq);
			
			var yimi = this.getChildByTag(TAG_SHOW);
			yimi.runAction(cc.fadeIn(3));
		}
		break;
		case TAG_INOCULATOR2:
			var yimi = this.getChildByTag(TAG_SHOW);
			var seq = cc.sequence(cc.fadeOut(3),cc.callFunc(function(){
				var show = new ShowTip("乙醚受热汽化,\n使活塞往外移",cc.p(750,250));
			},this));
			yimi.runAction(seq);
		break;
		}
	},
	flowNext:function(){
		gg.flow.next();
	},
});